home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / src / out-of-phase-102-c / OutOfPhase 1.02 Source / OutOfPhase Folder / InstrumentStructure.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-23  |  4.4 KB  |  130 lines  |  [TEXT/KAHL]

  1. /* InstrumentStructure.c */
  2. /*****************************************************************************/
  3. /*                                                                           */
  4. /*    Out Of Phase:  Digital Music Synthesis on General Purpose Computers    */
  5. /*    Copyright (C) 1994  Thomas R. Lawrence                                 */
  6. /*                                                                           */
  7. /*    This program is free software; you can redistribute it and/or modify   */
  8. /*    it under the terms of the GNU General Public License as published by   */
  9. /*    the Free Software Foundation; either version 2 of the License, or      */
  10. /*    (at your option) any later version.                                    */
  11. /*                                                                           */
  12. /*    This program is distributed in the hope that it will be useful,        */
  13. /*    but WITHOUT ANY WARRANTY; without even the implied warranty of         */
  14. /*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          */
  15. /*    GNU General Public License for more details.                           */
  16. /*                                                                           */
  17. /*    You should have received a copy of the GNU General Public License      */
  18. /*    along with this program; if not, write to the Free Software            */
  19. /*    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.              */
  20. /*                                                                           */
  21. /*    Thomas R. Lawrence can be reached at tomlaw@world.std.com.             */
  22. /*                                                                           */
  23. /*****************************************************************************/
  24.  
  25. #include "MiscInfo.h"
  26. #include "Audit.h"
  27. #include "Debug.h"
  28. #include "Definitions.h"
  29.  
  30. #include "InstrumentStructure.h"
  31. #include "Memory.h"
  32. #include "LFOListSpecifier.h"
  33. #include "OscillatorListSpecifier.h"
  34.  
  35.  
  36. struct InstrumentRec
  37.     {
  38.         /* this is the overall loudness factor for the instrument, which can be used */
  39.         /* to differentiate "loud" on a quite instrument vs. "loud" on a loud instrument. */
  40.         InstrNumberType                            OverallLoudness;
  41.  
  42.         /* list of LFO operators on the frequency */
  43.         struct LFOListSpecRec*            FrequencyLFOList;
  44.  
  45.         /* list of oscillators */
  46.         struct OscillatorListRec*        OscillatorList;
  47.     };
  48.  
  49.  
  50. /* create a new instrument specification record */
  51. InstrumentRec*                        NewInstrumentSpecifier(void)
  52.     {
  53.         InstrumentRec*            Instr;
  54.  
  55.         Instr = (InstrumentRec*)AllocPtrCanFail(sizeof(InstrumentRec),"InstrumentRec");
  56.         if (Instr == NIL)
  57.             {
  58.              FailurePoint1:
  59.                 return NIL;
  60.             }
  61.         Instr->OverallLoudness = 0;
  62.         Instr->FrequencyLFOList = NewLFOListSpecifier();
  63.         if (Instr->FrequencyLFOList == NIL)
  64.             {
  65.              FailurePoint2:
  66.                 ReleasePtr((char*)Instr);
  67.                 goto FailurePoint1;
  68.             }
  69.         Instr->OscillatorList = NewOscillatorListSpecifier();
  70.         if (Instr->OscillatorList == NIL)
  71.             {
  72.              FailurePoint3:
  73.                 DisposeLFOListSpecifier(Instr->FrequencyLFOList);
  74.                 goto FailurePoint2;
  75.             }
  76.         return Instr;
  77.     }
  78.  
  79.  
  80. /* dispose of the instrument specification record */
  81. void                                            DisposeInstrumentSpecification(InstrumentRec* Instr)
  82.     {
  83.         CheckPtrExistence(Instr);
  84.         DisposeOscillatorListSpecifier(Instr->OscillatorList);
  85.         DisposeLFOListSpecifier(Instr->FrequencyLFOList);
  86.         ReleasePtr((char*)Instr);
  87.     }
  88.  
  89.  
  90. /* get the overall loudness of the instrument */
  91. InstrNumberType                        GetInstrumentOverallLoudness(InstrumentRec* Instr)
  92.     {
  93.         CheckPtrExistence(Instr);
  94.         return Instr->OverallLoudness;
  95.     }
  96.  
  97.  
  98. /* put a new value for overall loudness */
  99. void                                            InstrumentSetOverallLoudness(InstrumentRec* Instr,
  100.                                                         double NewLoudness)
  101.     {
  102.         CheckPtrExistence(Instr);
  103.         Instr->OverallLoudness = NewLoudness;
  104.     }
  105.  
  106.  
  107. /* get the instrument's frequency LFO list */
  108. struct LFOListSpecRec*        GetInstrumentFrequencyLFOList(InstrumentRec* Instr)
  109.     {
  110.         CheckPtrExistence(Instr);
  111.         return Instr->FrequencyLFOList;
  112.     }
  113.  
  114.  
  115. /* get the instrument's oscillator list */
  116. struct OscillatorListRec*    GetInstrumentOscillatorList(InstrumentRec* Instr)
  117.     {
  118.         CheckPtrExistence(Instr);
  119.         return Instr->OscillatorList;
  120.     }
  121.  
  122.  
  123. /* resolve oscillator name references in modulation lists. returns False if there */
  124. /* are unresolvable names */
  125. MyBoolean                                    ResolveInstrOscillatorModulations(InstrumentRec* Instr)
  126.     {
  127.         CheckPtrExistence(Instr);
  128.         return ResolveOscillatorListModulators(Instr->OscillatorList);
  129.     }
  130.